package com.marvels.approve.loan.controller;

import com.github.pagehelper.PageInfo;
import com.marvels.approve.loan.dto.BsRepayPushDTO;
import com.marvels.approve.loan.service.ApprovalResultsService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * 
 * @author liuyk
 *
 */
@RestController
@RequestMapping("approve/bsRepayPush/service")
public class ApprovalResultsController {
	@Autowired
	private ApprovalResultsService approvalResultsService;
	@RequestMapping("selectResults")
	public MarvelsResultDTO selectResultsList(@RequestBody BsRepayPushDTO bsRepayPushDTO){
		PageInfo<BsRepayPushDTO> pageInfo = null;
		try {
			pageInfo = approvalResultsService.selectResultsList(bsRepayPushDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pageInfo);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"宝生审核结果异常");
		}
	}
	/**
	 * 宝生拒绝更换资金源
	 * @param bsRepayPushDTO
	 * @return
	 */
	@RequestMapping("updateBsFund")
	public MarvelsResultDTO updateBsFund(@RequestBody BsRepayPushDTO bsRepayPushDTO){
		Integer count = null;
		try {
			count = approvalResultsService.updateBsFund(bsRepayPushDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),count);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"宝生审核结果异常");
		}
	}
	/**
	 * 更换资金源需要做数据展示
	 * @param bsRepayPushDTO
	 * @return
	 */
	@RequestMapping("selectBsFund")
	public MarvelsResultDTO selectBsFund(@RequestBody BsRepayPushDTO bsRepayPushDTO){
		try {
			BsRepayPushDTO pushDTO = approvalResultsService.selectBsFund(bsRepayPushDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(), MarvelsErrorCode.SUCCESS.getDesc(),pushDTO);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果FAIL:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(), e.getMessage(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>宝生审核结果异常:", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(),"宝生审核结果异常");
		}
	}
	
}
